#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
#![feature(extern_types)]
extern crate libc;
use primary::alloc_testing::*;
use primary::slist::*;
use primary::compare_pointer::*;
use primary::compare_string::*;
use primary::compare_int::*;
use primary::hash_pointer::*;
use primary::hash_string::*;
use primary::hash_int::*;
extern "C" {
    pub type _SListEntry;
    fn __assert_fail(
        __assertion: *const libc::c_char,
        __file: *const libc::c_char,
        __line: libc::c_uint,
        __function: *const libc::c_char,
    ) -> !;
                                                                                    }
#[no_mangle]
pub static mut variable1: libc::c_int = 50 as libc::c_int;
#[no_mangle]
pub static mut variable2: libc::c_int = 0;
#[no_mangle]
pub static mut variable3: libc::c_int = 0;
#[no_mangle]
pub static mut variable4: libc::c_int = 0;
#[no_mangle]
pub extern "C" fn generate_list() -> *mut SListEntry {
    let mut list: *mut SListEntry = std::ptr::null_mut();

    assert!(
        !slist_append(&mut list, unsafe { &mut variable1 as *mut libc::c_int as SListValue }).is_null(),
        "slist_append(&list, &variable1) != NULL"
    );
    assert!(
        !slist_append(&mut list, unsafe { &mut variable2 as *mut libc::c_int as SListValue }).is_null(),
        "slist_append(&list, &variable2) != NULL"
    );
    assert!(
        !slist_append(&mut list, unsafe { &mut variable3 as *mut libc::c_int as SListValue }).is_null(),
        "slist_append(&list, &variable3) != NULL"
    );
    assert!(
        !slist_append(&mut list, unsafe { &mut variable4 as *mut libc::c_int as SListValue }).is_null(),
        "slist_append(&list, &variable4) != NULL"
    );

    list
}
#[no_mangle]
pub extern "C" fn test_slist_append() {
    let mut list: *mut SListEntry = std::ptr::null_mut();

    assert!(!slist_append(&mut list, unsafe { &mut variable1 as *mut libc::c_int as SListValue }).is_null());
    assert!(!slist_append(&mut list, unsafe { &mut variable2 as *mut libc::c_int as SListValue }).is_null());
    assert!(!slist_append(&mut list, unsafe { &mut variable3 as *mut libc::c_int as SListValue }).is_null());
    assert!(!slist_append(&mut list, unsafe { &mut variable4 as *mut libc::c_int as SListValue }).is_null());
    assert_eq!(slist_length(list), 4);
    assert_eq!(slist_nth_data(list, 0), unsafe { &mut variable1 as *mut libc::c_int as SListValue });
    assert_eq!(slist_nth_data(list, 1), unsafe { &mut variable2 as *mut libc::c_int as SListValue });
    assert_eq!(slist_nth_data(list, 2), unsafe { &mut variable3 as *mut libc::c_int as SListValue });
    assert_eq!(slist_nth_data(list, 3), unsafe { &mut variable4 as *mut libc::c_int as SListValue });
    slist_free(list);
}
#[no_mangle]
pub extern "C" fn test_slist_prepend() {
    let mut list: *mut SListEntry = std::ptr::null_mut();

    assert!(!slist_prepend(&mut list, unsafe { &mut variable1 as *mut libc::c_int as SListValue }).is_null());
    assert!(!slist_prepend(&mut list, unsafe { &mut variable2 as *mut libc::c_int as SListValue }).is_null());
    assert!(!slist_prepend(&mut list, unsafe { &mut variable3 as *mut libc::c_int as SListValue }).is_null());
    assert!(!slist_prepend(&mut list, unsafe { &mut variable4 as *mut libc::c_int as SListValue }).is_null());

    assert_eq!(slist_nth_data(list, 0), unsafe { &mut variable4 as *mut libc::c_int as SListValue });
    assert_eq!(slist_nth_data(list, 1), unsafe { &mut variable3 as *mut libc::c_int as SListValue });
    assert_eq!(slist_nth_data(list, 2), unsafe { &mut variable2 as *mut libc::c_int as SListValue });
    assert_eq!(slist_nth_data(list, 3), unsafe { &mut variable1 as *mut libc::c_int as SListValue });

    slist_free(list);
}
#[no_mangle]
pub extern "C" fn test_slist_free() {
    let mut list: *mut SListEntry = std::ptr::null_mut();

    list = generate_list();
    let list_box = unsafe { Box::from_raw(list) };
    slist_free(list);
    list = Box::into_raw(list_box);

    slist_free(std::ptr::null_mut());
}
#[no_mangle]
pub extern "C" fn test_slist_next() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut rover: *mut SListEntry = std::ptr::null_mut();

    
    unsafe {
        list = generate_list();
    }

    rover = list;

    
    unsafe {
        assert_eq!(slist_data(rover), &mut variable1 as *mut libc::c_int as SListValue, "slist_data(rover) == &variable1");
        rover = slist_next(rover);
        assert_eq!(slist_data(rover), &mut variable2 as *mut libc::c_int as SListValue, "slist_data(rover) == &variable2");
        rover = slist_next(rover);
        assert_eq!(slist_data(rover), &mut variable3 as *mut libc::c_int as SListValue, "slist_data(rover) == &variable3");
        rover = slist_next(rover);
        assert_eq!(slist_data(rover), &mut variable4 as *mut libc::c_int as SListValue, "slist_data(rover) == &variable4");
        rover = slist_next(rover);
        assert!(rover.is_null(), "rover == NULL");
        slist_free(list);
    }
}
#[no_mangle]
pub extern "C" fn test_slist_nth_entry() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut entry: *mut SListEntry = std::ptr::null_mut();

    list = generate_list();
    let list_box = unsafe { Box::from_raw(list) };

    entry = slist_nth_entry(list, 0);
    let entry_box_0 = unsafe { Box::from_raw(entry) };
    assert_eq!(slist_data(entry), unsafe { &mut variable1 as *mut libc::c_int as SListValue });
    entry = Box::into_raw(entry_box_0);

    entry = slist_nth_entry(list, 1);
    let entry_box_1 = unsafe { Box::from_raw(entry) };
    assert_eq!(slist_data(entry), unsafe { &mut variable2 as *mut libc::c_int as SListValue });
    entry = Box::into_raw(entry_box_1);

    entry = slist_nth_entry(list, 2);
    let entry_box_2 = unsafe { Box::from_raw(entry) };
    assert_eq!(slist_data(entry), unsafe { &mut variable3 as *mut libc::c_int as SListValue });
    entry = Box::into_raw(entry_box_2);

    entry = slist_nth_entry(list, 3);
    let entry_box_3 = unsafe { Box::from_raw(entry) };
    assert_eq!(slist_data(entry), unsafe { &mut variable4 as *mut libc::c_int as SListValue });
    entry = Box::into_raw(entry_box_3);

    entry = slist_nth_entry(list, 4);
    assert!(entry.is_null());

    entry = slist_nth_entry(list, 400);
    assert!(entry.is_null());

    list = Box::into_raw(list_box);
    slist_free(list);
}
#[no_mangle]
pub extern "C" fn test_slist_nth_data() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    unsafe {
        list = generate_list();
    }
    let list_box = unsafe { Box::from_raw(list) };
    assert_eq!(
        slist_nth_data(list, 0),
        unsafe { &mut variable1 as *mut libc::c_int as SListValue },
        "slist_nth_data(list, 0) == &variable1"
    );
    assert_eq!(
        slist_nth_data(list, 1),
        unsafe { &mut variable2 as *mut libc::c_int as SListValue },
        "slist_nth_data(list, 1) == &variable2"
    );
    assert_eq!(
        slist_nth_data(list, 2),
        unsafe { &mut variable3 as *mut libc::c_int as SListValue },
        "slist_nth_data(list, 2) == &variable3"
    );
    assert_eq!(
        slist_nth_data(list, 3),
        unsafe { &mut variable4 as *mut libc::c_int as SListValue },
        "slist_nth_data(list, 3) == &variable4"
    );
    assert!(
        slist_nth_data(list, 4).is_null(),
        "slist_nth_data(list, 4) == NULL"
    );
    assert!(
        slist_nth_data(list, 400).is_null(),
        "slist_nth_data(list, 400) == NULL"
    );
    list = Box::into_raw(list_box);
    unsafe {
        slist_free(list);
    }
}
#[no_mangle]
pub extern "C" fn test_slist_length() {
    let mut list: *mut SListEntry = std::ptr::null_mut();

    list = generate_list();
    let list_box = unsafe { Box::from_raw(list) };

    assert_eq!(slist_length(list), 4);

    slist_prepend(&mut list, unsafe { &mut variable1 as *mut libc::c_int as SListValue });

    assert_eq!(slist_length(list), 5);
    assert_eq!(slist_length(std::ptr::null_mut()), 0);

    list = Box::into_raw(list_box);
    slist_free(list);
}
#[no_mangle]
pub extern "C" fn test_slist_remove_entry() {
    let mut empty_list: *mut SListEntry = std::ptr::null_mut();
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut entry: *mut SListEntry = std::ptr::null_mut();

    
    unsafe {
        list = generate_list();
        entry = slist_nth_entry(list, 2);
    }

    assert_ne!(unsafe { slist_remove_entry(&mut list, entry) }, 0);
    assert_eq!(unsafe { slist_length(list) }, 3);

    
    unsafe {
        entry = slist_nth_entry(list, 0);
    }

    assert_ne!(unsafe { slist_remove_entry(&mut list, entry) }, 0);
    assert_eq!(unsafe { slist_length(list) }, 2);
    assert_eq!(unsafe { slist_remove_entry(&mut list, entry) }, 0);
    assert_eq!(unsafe { slist_remove_entry(&mut list, std::ptr::null_mut()) }, 0);
    assert_eq!(unsafe { slist_remove_entry(&mut empty_list, std::ptr::null_mut()) }, 0);

    
    unsafe {
        slist_free(list);
    }
}
#[no_mangle]
pub extern "C" fn test_slist_remove_data() {
    let mut entries: [libc::c_int; 13] = [
        89, 4, 23, 42, 4, 16, 15, 4, 8, 99, 50, 30, 4,
    ];
    let mut num_entries: libc::c_uint = (std::mem::size_of::<[libc::c_int; 13]>() as libc::c_ulong)
        .wrapping_div(std::mem::size_of::<libc::c_int>() as libc::c_ulong)
        as libc::c_uint;
    let mut val: libc::c_int = 0;
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut i: libc::c_uint = 0;

    while i < num_entries {
        unsafe {
            slist_prepend(
                &mut list,
                &mut *entries.as_mut_ptr().offset(i as isize) as *mut libc::c_int as SListValue,
            );
        }
        i = i.wrapping_add(1);
    }

    val = 0;
    assert_eq!(
        unsafe {
            slist_remove_data(
                &mut list,
                Some(int_equal),
                &mut val as *mut libc::c_int as SListValue,
            )
        },
        0
    );

    val = 56;
    assert_eq!(
        unsafe {
            slist_remove_data(
                &mut list,
                Some(int_equal),
                &mut val as *mut libc::c_int as SListValue,
            )
        },
        0
    );

    val = 8;
    assert_eq!(
        unsafe {
            slist_remove_data(
                &mut list,
                Some(int_equal),
                &mut val as *mut libc::c_int as SListValue,
            )
        },
        1
    );
    assert_eq!(unsafe { slist_length(list) }, num_entries.wrapping_sub(1));

    val = 4;
    assert_eq!(
        unsafe {
            slist_remove_data(
                &mut list,
                Some(int_equal),
                &mut val as *mut libc::c_int as SListValue,
            )
        },
        4
    );
    assert_eq!(unsafe { slist_length(list) }, num_entries.wrapping_sub(5));

    val = 89;
    assert_eq!(
        unsafe {
            slist_remove_data(
                &mut list,
                Some(int_equal),
                &mut val as *mut libc::c_int as SListValue,
            )
        },
        1
    );
    assert_eq!(unsafe { slist_length(list) }, num_entries.wrapping_sub(6));

    unsafe { slist_free(list); }
}
#[no_mangle]
pub extern "C" fn test_slist_sort() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut entries: [libc::c_int; 13] = [
        89, 4, 23, 42, 4, 16, 15, 4, 8, 99, 50, 30, 4,
    ];
    let mut sorted: [libc::c_int; 13] = [
        4, 4, 4, 4, 8, 15, 16, 23, 30, 42, 50, 89, 99,
    ];
    let num_entries: libc::c_uint = (std::mem::size_of::<[libc::c_int; 13]>() as libc::c_ulong)
        .wrapping_div(std::mem::size_of::<libc::c_int>() as libc::c_ulong)
        as libc::c_uint;
    let mut i: libc::c_uint = 0;

    i = 0;
    while i < num_entries {
        slist_prepend(
            &mut list,
            unsafe { &mut *entries.as_mut_ptr().offset(i as isize) as *mut libc::c_int as SListValue },
        );
        i = i.wrapping_add(1);
    }

    slist_sort(
        &mut list,
        Some(int_compare),
    );

    assert_eq!(unsafe { slist_length(list) }, num_entries, "slist_length(list) == num_entries");

    i = 0;
    while i < num_entries {
        let mut value: *mut libc::c_int = std::ptr::null_mut();
        value = unsafe { slist_nth_data(list, i) as *mut libc::c_int };
        assert_eq!(unsafe { *value }, sorted[i as usize], "*value == sorted[i]");
        i = i.wrapping_add(1);
    }

    unsafe {
        slist_free(list);
    }
    list = std::ptr::null_mut();

    slist_sort(
        &mut list,
        Some(int_compare),
    );

    assert!(list.is_null(), "list == NULL");
}
#[no_mangle]
pub extern "C" fn test_slist_find_data() {
    let mut entries: [libc::c_int; 10] = [
        89, 23, 42, 16, 15, 4, 8, 99, 50, 30,
    ];
    let mut num_entries: libc::c_int = (std::mem::size_of::<[libc::c_int; 10]>()
        as libc::c_ulong)
        .wrapping_div(std::mem::size_of::<libc::c_int>() as libc::c_ulong)
        as libc::c_int;
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut result: *mut SListEntry = std::ptr::null_mut();
    let mut i: libc::c_int = 0;
    let mut val: libc::c_int = 0;
    let mut data: *mut libc::c_int = std::ptr::null_mut();

    while i < num_entries {
        unsafe {
            slist_append(
                &mut list,
                &mut *entries.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                    as SListValue,
            );
        }
        i += 1;
    }

    i = 0;
    while i < num_entries {
        val = entries[i as usize];
        result = slist_find_data(
            list,
            Some(int_equal),
            &mut val as *mut libc::c_int as SListValue,
        );
        assert!(!result.is_null(), "result != NULL");
        unsafe {
            data = slist_data(result) as *mut libc::c_int;
            assert_eq!(*data, val, "*data == val");
        }
        i += 1;
    }

    val = 0;
    assert!(
        slist_find_data(
            list,
            Some(int_equal),
            &mut val as *mut libc::c_int as SListValue,
        )
        .is_null(),
        "slist_find_data(list, int_equal, &val) == NULL"
    );

    val = 56;
    assert!(
        slist_find_data(
            list,
            Some(int_equal),
            &mut val as *mut libc::c_int as SListValue,
        )
        .is_null(),
        "slist_find_data(list, int_equal, &val) == NULL"
    );

    slist_free(list);
}
#[no_mangle]
pub extern "C" fn test_slist_to_array() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut array: *mut *mut libc::c_void = std::ptr::null_mut();

    
    unsafe {
        list = generate_list();
    }

    
    unsafe {
        array = slist_to_array(list);
    }

    
    unsafe {
        assert!(
            *array.offset(0) == &mut variable1 as *mut libc::c_int as *mut libc::c_void,
            "array[0] == &variable1"
        );
        assert!(
            *array.offset(1) == &mut variable2 as *mut libc::c_int as *mut libc::c_void,
            "array[1] == &variable2"
        );
        assert!(
            *array.offset(2) == &mut variable3 as *mut libc::c_int as *mut libc::c_void,
            "array[2] == &variable3"
        );
        assert!(
            *array.offset(3) == &mut variable4 as *mut libc::c_int as *mut libc::c_void,
            "array[3] == &variable4"
        );
    }

    
    unsafe {
        alloc_test_free(array as *mut libc::c_void);
    }

    
    unsafe {
        slist_free(list);
    }
}
#[no_mangle]
pub extern "C" fn test_slist_iterate() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut iter: SListIterator = _SListIterator {
        prev_next: std::ptr::null_mut(),
        current: std::ptr::null_mut(),
    };
    let mut data: *mut libc::c_int = std::ptr::null_mut();
    let mut a: libc::c_int = 0;
    let mut i: libc::c_int = 0;
    let mut counter: libc::c_int = 0;

    list = std::ptr::null_mut();
    i = 0;
    while i < 50 {
        slist_prepend(&mut list, &mut a as *mut libc::c_int as SListValue);
        i += 1;
    }

    counter = 0;
    slist_iterate(&mut list, &mut iter);
    slist_iter_remove(&mut iter);

    while slist_iter_has_more(&mut iter) != 0 {
        data = slist_iter_next(&mut iter) as *mut libc::c_int;
        counter += 1;
        if counter % 2 == 0 {
            slist_iter_remove(&mut iter);
            slist_iter_remove(&mut iter);
        }
    }

    assert!(slist_iter_next(&mut iter).is_null(), "slist_iter_next(&iter) == SLIST_NULL");
    slist_iter_remove(&mut iter);
    assert_eq!(counter, 50, "counter == 50");
    assert_eq!(slist_length(list), 25, "slist_length(list) == 25");

    slist_free(list);

    list = std::ptr::null_mut();
    counter = 0;
    slist_iterate(&mut list, &mut iter);

    while slist_iter_has_more(&mut iter) != 0 {
        data = slist_iter_next(&mut iter) as *mut libc::c_int;
        counter += 1;
        if counter % 2 == 0 {
            slist_iter_remove(&mut iter);
        }
    }

    assert_eq!(counter, 0, "counter == 0");
}
#[no_mangle]
pub extern "C" fn test_slist_iterate_bad_remove() {
    let mut list: *mut SListEntry = std::ptr::null_mut();
    let mut iter: SListIterator = _SListIterator {
        prev_next: std::ptr::null_mut(),
        current: std::ptr::null_mut(),
    };
    let mut values: [libc::c_int; 49] = [0; 49];
    let mut i: libc::c_int = 0;
    let mut val: *mut libc::c_int = std::ptr::null_mut();

    list = std::ptr::null_mut();
    i = 0;
    while i < 49 {
        values[i as usize] = i;
        unsafe {
            slist_prepend(
                &mut list,
                &mut *values.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                    as SListValue,
            );
        }
        i += 1;
    }

    unsafe { slist_iterate(&mut list, &mut iter); }

    while unsafe { slist_iter_has_more(&mut iter) } != 0 {
        unsafe {
            val = slist_iter_next(&mut iter) as *mut libc::c_int;
            if *val % 2 == 0 {
                assert_ne!(
                    slist_remove_data(
                        &mut list,
                        Some(int_equal),
                        val as SListValue,
                    ),
                    0,
                    "slist_remove_data(&list, int_equal, val) != 0"
                );
                slist_iter_remove(&mut iter);
            }
        }
    }

    unsafe { slist_free(list); }
}
